package com.example.demo.base;

/**
 * @Author: xiatian
 * @CreateTime: 2021/9/23 2:40 下午
 * @Description:
 */
public class StringTest {
    public static void main(String[] args) {

        String s1 = new String("xyz");
        String s2 = "xyz";
        String s3 = s1.intern();

        System.out.println(s1 == s2);//false
        System.out.println(s1 == s3);//false
        System.out.println(s2 == s3);//true

        System.out.println('\n');
        String b1= new StringBuilder("ab").append("c").toString();
        String b3 = "abc";
        String b2 = b1.intern();

        System.out.println(b1 == b2); //false
        System.out.println(b1 == b3); //false
        System.out.println(b2 == b3); //true
        System.out.println(b1 == b1.intern());
    }
}
